package com.baobao.dao;

import com.baobao.domain.Askleave;

import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;

import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.skyway.spring.util.dao.AbstractJpaDao;

import org.springframework.dao.DataAccessException;

import org.springframework.stereotype.Repository;

import org.springframework.transaction.annotation.Transactional;

/**
 * DAO to manage Askleave entities.
 * 
 */
@Repository("AskleaveDAO")
@Transactional
public class AskleaveDAOImpl extends AbstractJpaDao<Askleave> implements
		AskleaveDAO {

	/**
	 * Set of entity classes managed by this DAO.  Typically a DAO manages a single entity.
	 *
	 */
	private final static Set<Class<?>> dataTypes = new HashSet<Class<?>>(Arrays.asList(new Class<?>[] { Askleave.class }));

	/**
	 * EntityManager injected by Spring for persistence unit BaoBao
	 *
	 */
	@PersistenceContext(unitName = "BaoBao")
	private EntityManager entityManager;

	/**
	 * Instantiates a new AskleaveDAOImpl
	 *
	 */
	public AskleaveDAOImpl() {
		super();
	}

	/**
	 * Get the entity manager that manages persistence unit 
	 *
	 */
	public EntityManager getEntityManager() {
		return entityManager;
	}

	/**
	 * Returns the set of entity classes managed by this DAO.
	 *
	 */
	public Set<Class<?>> getTypes() {
		return dataTypes;
	}

	/**
	 * JPQL Query - findAskleaveByApproveDetailContaining
	 *
	 */
	@Transactional
	public Set<Askleave> findAskleaveByApproveDetailContaining(String approveDetail) throws DataAccessException {

		return findAskleaveByApproveDetailContaining(approveDetail, -1, -1);
	}

	/**
	 * JPQL Query - findAskleaveByApproveDetailContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Askleave> findAskleaveByApproveDetailContaining(String approveDetail, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAskleaveByApproveDetailContaining", startResult, maxRows, approveDetail);
		return new LinkedHashSet<Askleave>(query.getResultList());
	}

	/**
	 * JPQL Query - findAskleaveByReason
	 *
	 */
	@Transactional
	public Set<Askleave> findAskleaveByReason(String reason) throws DataAccessException {

		return findAskleaveByReason(reason, -1, -1);
	}

	/**
	 * JPQL Query - findAskleaveByReason
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Askleave> findAskleaveByReason(String reason, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAskleaveByReason", startResult, maxRows, reason);
		return new LinkedHashSet<Askleave>(query.getResultList());
	}

	/**
	 * JPQL Query - findAskleaveByApproveDetail
	 *
	 */
	@Transactional
	public Set<Askleave> findAskleaveByApproveDetail(String approveDetail) throws DataAccessException {

		return findAskleaveByApproveDetail(approveDetail, -1, -1);
	}

	/**
	 * JPQL Query - findAskleaveByApproveDetail
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Askleave> findAskleaveByApproveDetail(String approveDetail, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAskleaveByApproveDetail", startResult, maxRows, approveDetail);
		return new LinkedHashSet<Askleave>(query.getResultList());
	}

	/**
	 * JPQL Query - findAskleaveByDetailContaining
	 *
	 */
	@Transactional
	public Set<Askleave> findAskleaveByDetailContaining(String detail) throws DataAccessException {

		return findAskleaveByDetailContaining(detail, -1, -1);
	}

	/**
	 * JPQL Query - findAskleaveByDetailContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Askleave> findAskleaveByDetailContaining(String detail, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAskleaveByDetailContaining", startResult, maxRows, detail);
		return new LinkedHashSet<Askleave>(query.getResultList());
	}

	/**
	 * JPQL Query - findAskleaveByApproveTime
	 *
	 */
	@Transactional
	public Set<Askleave> findAskleaveByApproveTime(java.util.Calendar approveTime) throws DataAccessException {

		return findAskleaveByApproveTime(approveTime, -1, -1);
	}

	/**
	 * JPQL Query - findAskleaveByApproveTime
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Askleave> findAskleaveByApproveTime(java.util.Calendar approveTime, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAskleaveByApproveTime", startResult, maxRows, approveTime);
		return new LinkedHashSet<Askleave>(query.getResultList());
	}

	/**
	 * JPQL Query - findAskleaveByStartTime
	 *
	 */
	@Transactional
	public Set<Askleave> findAskleaveByStartTime(java.util.Calendar startTime) throws DataAccessException {

		return findAskleaveByStartTime(startTime, -1, -1);
	}

	/**
	 * JPQL Query - findAskleaveByStartTime
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Askleave> findAskleaveByStartTime(java.util.Calendar startTime, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAskleaveByStartTime", startResult, maxRows, startTime);
		return new LinkedHashSet<Askleave>(query.getResultList());
	}

	/**
	 * JPQL Query - findAskleaveByApproveResultContaining
	 *
	 */
	@Transactional
	public Set<Askleave> findAskleaveByApproveResultContaining(String approveResult) throws DataAccessException {

		return findAskleaveByApproveResultContaining(approveResult, -1, -1);
	}

	/**
	 * JPQL Query - findAskleaveByApproveResultContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Askleave> findAskleaveByApproveResultContaining(String approveResult, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAskleaveByApproveResultContaining", startResult, maxRows, approveResult);
		return new LinkedHashSet<Askleave>(query.getResultList());
	}

	/**
	 * JPQL Query - findAskleaveByTeacherPhoneContaining
	 *
	 */
	@Transactional
	public Set<Askleave> findAskleaveByTeacherPhoneContaining(String teacherPhone) throws DataAccessException {

		return findAskleaveByTeacherPhoneContaining(teacherPhone, -1, -1);
	}

	/**
	 * JPQL Query - findAskleaveByTeacherPhoneContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Askleave> findAskleaveByTeacherPhoneContaining(String teacherPhone, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAskleaveByTeacherPhoneContaining", startResult, maxRows, teacherPhone);
		return new LinkedHashSet<Askleave>(query.getResultList());
	}

	/**
	 * JPQL Query - findAskleaveByEndTime
	 *
	 */
	@Transactional
	public Set<Askleave> findAskleaveByEndTime(java.util.Calendar endTime) throws DataAccessException {

		return findAskleaveByEndTime(endTime, -1, -1);
	}

	/**
	 * JPQL Query - findAskleaveByEndTime
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Askleave> findAskleaveByEndTime(java.util.Calendar endTime, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAskleaveByEndTime", startResult, maxRows, endTime);
		return new LinkedHashSet<Askleave>(query.getResultList());
	}

	/**
	 * JPQL Query - findAskleaveByParentPhone
	 *
	 */
	@Transactional
	public Set<Askleave> findAskleaveByParentPhone(String parentPhone) throws DataAccessException {

		return findAskleaveByParentPhone(parentPhone, -1, -1);
	}

	/**
	 * JPQL Query - findAskleaveByParentPhone
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Askleave> findAskleaveByParentPhone(String parentPhone, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAskleaveByParentPhone", startResult, maxRows, parentPhone);
		return new LinkedHashSet<Askleave>(query.getResultList());
	}

	/**
	 * JPQL Query - findAskleaveByDetail
	 *
	 */
	@Transactional
	public Set<Askleave> findAskleaveByDetail(String detail) throws DataAccessException {

		return findAskleaveByDetail(detail, -1, -1);
	}

	/**
	 * JPQL Query - findAskleaveByDetail
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Askleave> findAskleaveByDetail(String detail, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAskleaveByDetail", startResult, maxRows, detail);
		return new LinkedHashSet<Askleave>(query.getResultList());
	}

	/**
	 * JPQL Query - findAskleaveByApplyTime
	 *
	 */
	@Transactional
	public Set<Askleave> findAskleaveByApplyTime(java.util.Calendar applyTime) throws DataAccessException {

		return findAskleaveByApplyTime(applyTime, -1, -1);
	}

	/**
	 * JPQL Query - findAskleaveByApplyTime
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Askleave> findAskleaveByApplyTime(java.util.Calendar applyTime, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAskleaveByApplyTime", startResult, maxRows, applyTime);
		return new LinkedHashSet<Askleave>(query.getResultList());
	}

	/**
	 * JPQL Query - findAskleaveByReasonContaining
	 *
	 */
	@Transactional
	public Set<Askleave> findAskleaveByReasonContaining(String reason) throws DataAccessException {

		return findAskleaveByReasonContaining(reason, -1, -1);
	}

	/**
	 * JPQL Query - findAskleaveByReasonContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Askleave> findAskleaveByReasonContaining(String reason, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAskleaveByReasonContaining", startResult, maxRows, reason);
		return new LinkedHashSet<Askleave>(query.getResultList());
	}

	/**
	 * JPQL Query - findAskleaveByParentPhoneContaining
	 *
	 */
	@Transactional
	public Set<Askleave> findAskleaveByParentPhoneContaining(String parentPhone) throws DataAccessException {

		return findAskleaveByParentPhoneContaining(parentPhone, -1, -1);
	}

	/**
	 * JPQL Query - findAskleaveByParentPhoneContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Askleave> findAskleaveByParentPhoneContaining(String parentPhone, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAskleaveByParentPhoneContaining", startResult, maxRows, parentPhone);
		return new LinkedHashSet<Askleave>(query.getResultList());
	}

	/**
	 * JPQL Query - findAskleaveByStatusContaining
	 *
	 */
	@Transactional
	public Set<Askleave> findAskleaveByStatusContaining(String status) throws DataAccessException {

		return findAskleaveByStatusContaining(status, -1, -1);
	}

	/**
	 * JPQL Query - findAskleaveByStatusContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Askleave> findAskleaveByStatusContaining(String status, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAskleaveByStatusContaining", startResult, maxRows, status);
		return new LinkedHashSet<Askleave>(query.getResultList());
	}

	/**
	 * JPQL Query - findAskleaveByPrimaryKey
	 *
	 */
	@Transactional
	public Askleave findAskleaveByPrimaryKey(String parentPhone, String studentId, java.util.Calendar applyTime) throws DataAccessException {

		return findAskleaveByPrimaryKey(parentPhone, studentId, applyTime, -1, -1);
	}

	/**
	 * JPQL Query - findAskleaveByPrimaryKey
	 *
	 */

	@Transactional
	public Askleave findAskleaveByPrimaryKey(String parentPhone, String studentId, java.util.Calendar applyTime, int startResult, int maxRows) throws DataAccessException {
		try {
			Query query = createNamedQuery("findAskleaveByPrimaryKey", startResult, maxRows, parentPhone, studentId, applyTime);
			return (com.baobao.domain.Askleave) query.getSingleResult();
		} catch (NoResultException nre) {
			return null;
		}
	}

	/**
	 * JPQL Query - findAllAskleaves
	 *
	 */
	@Transactional
	public Set<Askleave> findAllAskleaves() throws DataAccessException {

		return findAllAskleaves(-1, -1);
	}

	/**
	 * JPQL Query - findAllAskleaves
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Askleave> findAllAskleaves(int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAllAskleaves", startResult, maxRows);
		return new LinkedHashSet<Askleave>(query.getResultList());
	}

	/**
	 * JPQL Query - findAskleaveByApproveResult
	 *
	 */
	@Transactional
	public Set<Askleave> findAskleaveByApproveResult(String approveResult) throws DataAccessException {

		return findAskleaveByApproveResult(approveResult, -1, -1);
	}

	/**
	 * JPQL Query - findAskleaveByApproveResult
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Askleave> findAskleaveByApproveResult(String approveResult, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAskleaveByApproveResult", startResult, maxRows, approveResult);
		return new LinkedHashSet<Askleave>(query.getResultList());
	}

	/**
	 * JPQL Query - findAskleaveByStudentIdContaining
	 *
	 */
	@Transactional
	public Set<Askleave> findAskleaveByStudentIdContaining(String studentId) throws DataAccessException {

		return findAskleaveByStudentIdContaining(studentId, -1, -1);
	}

	/**
	 * JPQL Query - findAskleaveByStudentIdContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Askleave> findAskleaveByStudentIdContaining(String studentId, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAskleaveByStudentIdContaining", startResult, maxRows, studentId);
		return new LinkedHashSet<Askleave>(query.getResultList());
	}

	/**
	 * JPQL Query - findAskleaveByStudentId
	 *
	 */
	@Transactional
	public Set<Askleave> findAskleaveByStudentId(String studentId) throws DataAccessException {

		return findAskleaveByStudentId(studentId, -1, -1);
	}

	/**
	 * JPQL Query - findAskleaveByStudentId
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Askleave> findAskleaveByStudentId(String studentId, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAskleaveByStudentId", startResult, maxRows, studentId);
		return new LinkedHashSet<Askleave>(query.getResultList());
	}

	/**
	 * JPQL Query - findAskleaveByTeacherPhone
	 *
	 */
	@Transactional
	public Set<Askleave> findAskleaveByTeacherPhone(String teacherPhone) throws DataAccessException {

		return findAskleaveByTeacherPhone(teacherPhone, -1, -1);
	}

	/**
	 * JPQL Query - findAskleaveByTeacherPhone
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Askleave> findAskleaveByTeacherPhone(String teacherPhone, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAskleaveByTeacherPhone", startResult, maxRows, teacherPhone);
		return new LinkedHashSet<Askleave>(query.getResultList());
	}

	/**
	 * JPQL Query - findAskleaveByStatus
	 *
	 */
	@Transactional
	public Set<Askleave> findAskleaveByStatus(String status) throws DataAccessException {

		return findAskleaveByStatus(status, -1, -1);
	}

	/**
	 * JPQL Query - findAskleaveByStatus
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Askleave> findAskleaveByStatus(String status, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAskleaveByStatus", startResult, maxRows, status);
		return new LinkedHashSet<Askleave>(query.getResultList());
	}

	/**
	 * Used to determine whether or not to merge the entity or persist the entity when calling Store
	 * @see store
	 * 
	 *
	 */
	public boolean canBeMerged(Askleave entity) {
		return true;
	}
}
